package coreservlets.ch16;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class ScopedVars extends HttpServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		req.setAttribute("attribute1", "First Value");
		HttpSession session = req.getSession();
		session.setAttribute("attribute2", "Second Value");
		ServletContext application = getServletContext();
		application.setAttribute("attribute3", new java.util.Date());
		req.setAttribute("repeated", "Request");
		session.setAttribute("repeated", "Session");
		application.setAttribute("repeated", "ServletContext");
		RequestDispatcher dispatcher = req
				.getRequestDispatcher("/el/scoped-vars.jsp");
		dispatcher.forward(req, resp);
	}
}
